from typing import List

from langchain.agents import create_react_agent, AgentExecutor
from langchain_core.prompts import PromptTemplate
from langchain_core.tools import tool
from langchain_ollama import ChatOllama

from common_config import CHAT_OLLAMA_MODEL
from tool_call.ollama_prompt import TOOL_CALL_TEMPLATE


@tool
def validate_user(user_id: str, addressed: List) -> bool:
    """validate user using historical addresses.

    Args:
        user_id: (int) the user id
        addressed: Previous addresses.
    """
    print(f"Validating user {user_id} with addresses: {addressed}")

    return True


llm = ChatOllama(
    model=CHAT_OLLAMA_MODEL,
    temperature=0,
)

prompt = PromptTemplate.from_template(TOOL_CALL_TEMPLATE)
tools = [validate_user]

agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

question = """Could you validate user 123? They previously lived at
    123 Fake St in Boston MA and 234 Pretend Boulevard in
    Huuston TX
    /nothink"""

response = agent_executor.invoke({"input": question})

print(response)
print(response.tool_calls)
